<form action="" method="POST" id="addTrainingfrm" name = "addTrainingfrm" autocomplete="off" enctype="multipart/form-data">
	<?php
	echo $this->formHidden("selectValueTreeImg",$this->selectValueTreeImg,null);
	echo $this->formHidden("tempId",'',null);
	echo $this->formHidden("td03id",$this->td03id,null);
	echo $this->formHidden("td01",'',null);
	echo $this->formHidden("hdnpath",'',null);
	echo $this->formHidden("hdn_chk_attach",'',null);
	echo $this->formHidden("hdn_chk_attach_flash",'',null);
	

	?>
	<div id = "form-container"> 
		<div id = "form-content">		
			<div id = "form-header-left" style="width:100%;">
				CẬP NHẬT TÀI LIỆU
			</div>			
			<div>
				<div class = "tile_l2">Thông tin cơ bản</div>
				<div>
					<label class = "normal_label">Tên tài liệu<small class="normal_starmark">*</small></label>
					<input id = "td02" name = "td02" class = "textbox_tab" message = "Bạn phải nhập tên bài giảng" optional="false"/>
				</div>	
				<div>
					<label class = "normal_label">Tài liệu thuộc<small class="normal_starmark">*</small></label>	
					<input type="text" name="td03" id="td03" readonly="" class="textbox_tab input1" value="<?= $this->td03name;?>"  message = "Bạn phải xác định bài giảng thuộc" optional="false">
					<img src="<?php echo $this->baseUrl;?>/images/find.gif" class="normal_image imgGetDep" />
				</div>
                <div style="display:none;">
                    <label class = "normal_label"></label>
                    <input type="checkbox" checked id="save_path" name="save_path">
                    <label class = "normal_label" style="float:none;" for="save_path">Lưu đường dẫn tài liệu</label>
                </div>
				<div>
					<label class = "normal_label">Danh mục tài liệu</label>
					<div>
						<select multiple = "multiple" class="textbox" id="td20" name="td20" class="textbox normal_label" optional = "true"><?php
							$arrClass = $this->arrClass;
							echo Efy_Library::_generateSelectOption($arrClass,'C_CODE','C_CODE','C_NAME','');?>
						</select>
					</div>
				</div>
				<div class="tacgia">
					<label class = "normal_label">Tác giả</label>
					<div>
						<select class="textbox" multiple = "multiple" id="td21" name="td21" class="textbox normal_label" optional = "true" style="width: 60%;"><?php
							$arrTacgia = $this->arrTacgia;
							echo Efy_Library::_generateSelectOption($arrTacgia,'C_CODE','C_CODE','C_NAME','');?>
						</select>
					</div>
				</div>
				<div>
					<label class = "normal_label">Nhóm người xem tài liệu</label>
					<div>
						<select class="textbox" multiple = "multiple" id="groupuser_view" name="groupuser_view" class="textbox normal_label" optional = "true" style="width: 60%;"><?php
							$arrGroupUserView = $this->arrGroupUserView;
							echo Efy_Library::_generateSelectOption($arrGroupUserView,'C_CODE','C_CODE','C_NAME','');?>
						</select>
					</div>
				</div>

				<div>
					<label class = "normal_label">Nhóm người download tài liệu</label>
					<div>
						<select class="textbox" multiple = "multiple" id="groupuser_download" name="groupuser_download" class="textbox normal_label" optional = "true" style="width: 60%;"><?php
							$arrGroupUserDownload = $this->arrGroupUserDownload;
							echo Efy_Library::_generateSelectOption($arrGroupUserDownload,'C_CODE','C_CODE','C_NAME','');?>
						</select>
					</div>
				</div>
				<div>
					<label class = "normal_label">Nội dung mô tả</label>
					<textarea class = "textbox" name = "td17" id = "td17"></textarea>
				</div>
                <div id = "div_attach_file_thumb" style="padding-bottom:5px;">
                    <label class = "normal_label" style="width:25%; float:left">Hình ảnh đại diện</label>
                    <?php echo $this->attachFileThumbnail;?>
                </div>
				<div id = "div_attach_file">
					<?php echo $this->attachFile;?>		
				</div>
				<div id = "div_attach_file_flash">
					<?php echo $this->attachFileFlash;?>		
				</div>
				
				<div class = "tile_l2">Phân quyền khai thác tài liệu</div>
				<div>
					<input type = "radio" name = "td06" id = "cl" value = "cl"/>
					<label for = "cl" class = "normal_label inline">Đăng tài liệu</label>
				</div>
				<div id = "permision_view" class = "td06" style="margin-left: 3%;">
					<label class = "normal_label">Quyền xem</label>
					<div>
						<input type = "radio" name = "td15" id = "all" value = "ALL" checked />
						<label for = "all" class = "normal_label inline">Toàn bộ</label>					
						<div>
							<input type = "radio" name = "td15" id = "staff" value = "STAFF">
							<label for = "staff" class = "normal_label inline">Giới hạn cán bộ</label>
							<div id="ajax_staff15">	
							</div>
						</div>
					</div>
				</div>
				<div id = "permision_download" class = "td06" style="margin-left: 3%;">
					<label class = "normal_label">Quyền tải file</label>
					<div>
						<input type = "radio" name = "td15_down" id = "all_user" value = "ALL" checked />
						<label for = "all_user" class = "normal_label inline">Toàn bộ</label>					
						<div>
							<input type = "radio" name = "td15_down" id = "staff_down" value = "STAFF">
							<label for = "staff_down" class = "normal_label inline">Giới hạn cán bộ</label>
							<div id="ajax_staff16">
							</div>
						</div>
					</div>					
				</div>				
			</div>
		</div>
		<div id="button">
			<input  type="button" style="margin: 0 0 20px 3px;" id="add_new" name="add" class="link-button clsave" value="Ghi & Thêm mới" action ="next" />
			<input  type="button" style="margin: 0 0 20px 3px;" id="add_back" name="btn_quaylai" class="link-button clsave" value="Ghi & quay lại" action ="back" />
			<input  type="button" style="margin: 0 0 20px 3px;" id="back" name="btn_quaylai" class="link-button clback" value="Quay lại"/>
		</div>
	</div>
</form>
<div id ="dialog" title = "Chọn đối tượng">
	<div id="treeDialog"></div>
</div>
<script type="text/javascript">
	$( "#dialog" ).dialog({
		autoOpen: false,					
        modal: true,
        resizable: true,
        width:800,
        height:600,
        autoResize: false,      
        dialogClass:'dialog-class',        
        draggable:true,
        buttons: [
			    {
			        text: "Đóng",
			        click: function() { 
			        	if($('form#addTrainingfrm input#tempId').val() != ''){
			        		jAlert('Bạn chưa được quyền thêm tài liệu trong thư mục ' + $('form#addTrainingfrm input#tempId').val(), 'Thông báo !');
			        		return false;
			        	}else{
			        		$(this).dialog("close"); 
			        	}	
			    	}
			    }
			]
	});			
	$('div.td06').hide();
	$("#ajax_staff15").hide();
	$('input[name="td15"]').click(function(){		
		$("#ajax_staff15").hide();
		var td15 =$('input[name="td15"]:checked').val();		
		if(td15 == 'STAFF'){
			$("#ajax_staff15").show();
		 	if($.trim($("#ajax_staff15").html()) == ''){			
				$.post("../ajaxstaff/",function(data){
					$("#ajax_staff15").html(data);					
				});
			}
		}		
		return true;
	});
	$("#ajax_staff16").hide();
	$('input[name="td15_down"]').click(function(){		
		$("#ajax_staff16").hide();
		var td15 =$('input[name="td15_down"]:checked').val();		
		if(td15 == 'STAFF'){
			$("#ajax_staff16").show();
		 	if($.trim($("#ajax_staff16").html()) == ''){			
				$.post("../ajaxstaffdown/",function(data){
					$("#ajax_staff16").html(data);					
				});
			}
		}
		return true;
	});	
	$('input[name="td06"]').click(function(){
		var td06 =$('input[name="td06"]:checked').val();	
		$('div.td06').hide();
		$('#cboldt').attr('optional','true');
		$('div#permision_view').show();
		$('div#permision_download').show();
		$('div#ldd').show();	
		return true;
	})

	$("select#td20").multiselect({
		header: false,
       	width: "90%",
        noneSelectedText: 'Chọn danh mục sách',
		selectedText: '# danh mục sách',
        selectedList:15,
        checkAllText:'Chọn tất cả',
        uncheckAllText:'Bỏ chọn tất cả',
        valueList: ''
    }).multiselectfilter(); 

	$("select#td21").multiselect({
		header: true,
       	width: "90%",
        noneSelectedText: 'Chọn tác giả',
		selectedText: '# tác giả',
        selectedList:15,
        checkAllText:'Chọn tất cả',
        uncheckAllText:'Bỏ chọn tất cả',
        valueList: ''
    }).multiselectfilter({
		filter: function(event, matches){
			if( !matches.length ){
				// do something
			}
		}
	}); 
	
	$("select#groupuser_view").multiselect({
		header: false,
       	width: "90%",
        noneSelectedText: 'Chọn nhóm người dùng',
		selectedText: '# nhóm người dùng',
        selectedList:15,
        checkAllText:'Chọn tất cả',
        uncheckAllText:'Bỏ chọn tất cả',
        valueList: ''
    }).multiselectfilter(); 
	
	$("select#groupuser_download").multiselect({
		header: false,
       	width: "90%",
        noneSelectedText: 'Chọn nhóm người dùng',
		selectedText: '# nhóm người dùng',
        selectedList:15,
        checkAllText:'Chọn tất cả',
        uncheckAllText:'Bỏ chọn tất cả',
        valueList: ''
    }).multiselectfilter(); 
	
    $('#td02').focus();
    $('document').ready(function (){	
		$('#td08').mask("9?999",{placeholder:""});		
		$('#td09').mask("9?999",{placeholder:""});		
	});	
	//Bind handler to form		
	$('#addTrainingfrm').bind('resetValues', function(event, option){
        var srcdefault ='<img class="" src="'+baseUrl+'/public/attach-file/default/default.jpg">';
        $('.successThumbnail').html(srcdefault);
		$('#cboldt').attr('optional','true');
		$('form#addTrainingfrm #td02').val('');
		$('form#addTrainingfrm #td01').val('');
		$('form#addTrainingfrm #td20').val('');
		$("select#td20").multiselect('refresh');
		$('form#addTrainingfrm #td17').val('');
		$('form#addTrainingfrm #listAttach').html('');			
		$('form#addTrainingfrm input[name="td06"]').attr('checked',false);
		$('div.td06').hide();		
		$('div#ajax_staff15').html('');
		$('div#ajax_staff21').html('');
		$('form#addTrainingfrm input[name="chk_unit_id"]').attr('checked',false);
		$('form#addTrainingfrm input[name="chk_staff_id"]').attr('checked',false);
		$('form#addTrainingfrm #div_obj').hide();
		$('form#addTrainingfrm #cboldt').val('');
		$('form#addTrainingfrm input[name="td15"]').attr('checked',false);
		$('form#addTrainingfrm input#all').attr('checked',true);
		if(option == 'edit'){
			$('form#addTrainingfrm #td03').val('');
			$('form#addTrainingfrm #td03id').val('');
			$('form#addTrainingfrm #selectValueTreeImg').val('');
			$('form#addTrainingfrm #td08').val('');
			$('form#addTrainingfrm #td09').val('');		
		}else if(option == 'add'){
			$('form#addTrainingfrm #td03').val($('form#TrainingIndexFrm #td03name').val());
			$('form#addTrainingfrm #td03id').val($('form#TrainingIndexFrm #td03').val());
			$('form#addTrainingfrm #selectValueTreeImg').val($('form#TrainingIndexFrm #td03').val());
			$('form#addTrainingfrm #td08').val(currentYear);
			$('form#addTrainingfrm #td09').val(currentYear + 1);		
		}
	});	

	$('#addTrainingfrm').bind('update', function(event,arrValue){
		$('form#addTrainingfrm #td01').val(arrValue.TD01);	
		$('form#addTrainingfrm #td02').val(arrValue.TD02);
		$('form#addTrainingfrm #td08').val(arrValue.TD08);
		$('form#addTrainingfrm #td09').val(arrValue.TD09);
		$('form#addTrainingfrm #td17').val(arrValue.TD17);		
			
		$('form#addTrainingfrm #td03').val(arrValue.TD03NAME);
		$('form#addTrainingfrm #td21').val(arrValue.C_TAC_GIA);		
		$('form#addTrainingfrm #selectValueTreeImg').val(arrValue.TD03);		
		arrValue.TD20 = ',' + arrValue.TD20 + ',';		
		$('form#addTrainingfrm #td20 option').each(function(){
			if(arrValue.TD20.indexOf(','+this.value+',') >= 0){				
				$(this).attr('selected', true);			
			} 	
		});
		$("select#td20").multiselect('refresh');
			//td21 tac gia
		arrValue.C_TAC_GIA = ',' + arrValue.C_TAC_GIA + ',';		
		$('form#addTrainingfrm #td21 option').each(function(){
			if(arrValue.C_TAC_GIA.indexOf(','+this.value+',') >= 0){				
				$(this).attr('selected', true);			
			} 	
		});
		$("select#td21").multiselect('refresh');
		//Nhom nguoi xem
		arrValue.C_GROUP_USER_VIEW = '!@!' + arrValue.C_GROUP_USER_VIEW + '!@!';
		$('form#addTrainingfrm #groupuser_view option').each(function(){
			if(arrValue.C_GROUP_USER_VIEW.indexOf('!@!'+this.value+'!@!') >= 0){
				$(this).attr('selected', true);
			}
		});
		$("select#groupuser_view").multiselect('refresh');
		//Nhom nguoi down
		arrValue.C_GROUP_USER_DOWN = '!@!' + arrValue.C_GROUP_USER_DOWN + '!@!';
		$('form#addTrainingfrm #groupuser_download option').each(function(){
			if(arrValue.C_GROUP_USER_DOWN.indexOf('!@!'+this.value+'!@!') >= 0){
				$(this).attr('selected', true);
			}
		});
		$("select#groupuser_download").multiselect('refresh');
		
        $('form#addTrainingfrm #div_attach_file_thumb').html(arrValue.ATTACH_FILE_THUMB);
		$('form#addTrainingfrm #div_attach_file').html(arrValue.C_FILE_DOCUMENT_HTML);
		$('form#addTrainingfrm #div_attach_file_flash').html(arrValue.C_FILE_FLASH_HTML);
		$('form#addTrainingfrm #hdn_chk_attach').val(arrValue.C_FILE_DOCUMENT);
		$('form#addTrainingfrm #hdn_chk_attach_flash').val(arrValue.C_FILE_FLASH);
		
		switch(arrValue.TD06){			
			case 'CHUYEN_LUU':			
				$('form#addTrainingfrm input[name="td06"][value="cl"]').attr('checked',true);
				//alert(arrValue.TD15);
				switch(arrValue.TD15){
					case 'ALL':
						$('form#addTrainingfrm input[name="td15"][value="ALL"]').attr('checked',true);		
						break;
					case 'STAFF':
						$('form#addTrainingfrm input[name="td15"][value="STAFF"]').attr('checked',true);		
						$('form#addTrainingfrm #ajax_staff15').html(arrValue.TD21TREE);						
						break;
				}
				switch(arrValue.C_DOWN_PERMISSION){
					case 'ALL':
						$('form#addTrainingfrm input[name="td15_down"][value="ALL"]').attr('checked',true);		
						break;
					case 'STAFF':
						$('form#addTrainingfrm input[name="td15_down"][value="STAFF"]').attr('checked',true);		
						$('form#addTrainingfrm #ajax_staff16').html(arrValue.TD24TREE);						
						break;
				}
				$('div#permision_view').show();
				$('div#permision_download').show();
				$('div#ldd').show();
				break;
		}
	});
	$('.imgGetDep').click(function(){
		myTrainingIndex.getDep();
	});
	$('#add_new').click(function(){
		myTrainingIndex.save('addNew');
	});	
	$('#add_back').click(function(){
		myTrainingIndex.save('back');
	});
	$('#back').click(function(){
		myTrainingIndex.ldmod();
	});	
</script>
<style type="text/css">
.ui-dialog .ui-dialog-title {
    float: left;
    margin: 0.1em 0;
    text-align: center;
}
.ui-multiselect-filter input {width:150px;}
div.tacgia .ui-multiselect-checkboxes li {
    display: inline-block;
    width: 
}

div#form-content .ui-multiselect-checkboxes label {
    width: 220px;
}
</style>